package models;

import java.lang.reflect.*;
import com.google.gson.*;

public class PostSerializer implements JsonSerializer<Post> {

	public JsonElement serialize(Post p, Type typeOfPost, JsonSerializationContext context) {
		JsonObject obj = new JsonObject();
		
		obj.addProperty("id", p.id);
		obj.addProperty("title", p.title);
		obj.addProperty("content", p.content);
		obj.addProperty("postDate", p.postDate.toString());
		obj.addProperty("authorid", p.author.id);
		obj.addProperty("authorName", p.author.getRepresName());
		obj.addProperty("authorHasAvatar", p.author.hasPhoto());
		
		return obj;
	}
}